package weather.util.dictionary;

import java.io.*;
import java.util.*;

import org.apache.poi.ss.usermodel.*;

/**
 * @author Jerzy Mazurek WEiTI PW
 */
public abstract class AbstractSimpleDictionary<Entry> extends AbstractDictionary
{
	public void loadFromXlsFile(File path, int sheetNumber) throws IOException
	{
		Workbook wb = openWorkbook(path);
		Sheet sheet = wb.getSheetAt(sheetNumber);
		
		int columnNum = sheet.getRow(sheet.getFirstRowNum()).getFirstCellNum();
		
		for (int r = sheet.getFirstRowNum(); r <= sheet.getLastRowNum(); ++r)
		{
			entries.add(newEntry(sheet.getRow(r).getCell(columnNum).getStringCellValue()));
		}
	}

	public boolean containsEntry(Entry entry)
	{
		return entries.contains(entry); 
	}
	
	public Set<Entry> getEntries()
	{
		return entries;
	}
	
	protected abstract Entry newEntry(String line);
	
	private Set<Entry> entries = new HashSet<Entry>();
}
